﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Concurrent;

namespace ScanQrCodeDemo.Web.Utility
{
    public class RedisHelper
    {
        private readonly ConnectionMultiplexer redis;


        // 模拟redis
        private static List<LoginModel> loginModels = new List<LoginModel>();

        public RedisHelper()
        {
            //this.redis = ConnectionMultiplexer.Connect("localhost");
        }

        public LoginModel GetSession(Guid guid)
        {
            var session = loginModels.Find(t => t.Id == guid);
            return session;
        }

        public Guid CreateNew()
        {
            Guid guid = Guid.NewGuid();
            LoginModel session = new LoginModel()
            {
                Id = guid
            };
            loginModels.Add(session);
            return guid;
        }

        public void UpdateScanState(Guid guid)
        {
            var session = GetSession(guid);
            session.HasScaned = true;
        }


        public void Login(Guid guid, string userId)
        {
            var session = GetSession(guid);
            session.UserId = userId;
        }

        public void Delete(Guid guid)
        {
            loginModels.Remove(GetSession(guid));
        }
    }
}
